package roboticsfmw.sample.hardware;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

public class JoystickCanvas extends Canvas {

	private static final long serialVersionUID = 1L;

	private int xCursor;
	private int yCursor;
	
	public JoystickCanvas() {
		setBackground(Color.BLACK);
	}
	
	public void setXY(int x, int y) {
		this.xCursor=x;
		this.yCursor=y;
		repaint();
	}
	
	public void setX(int x) {
		setXY(x,yCursor);
	}
	
	public void setY(int y) {
		setXY(xCursor,y);
	}
	
	@Override
	public void paint(Graphics g) {
		Graphics2D g2d = (Graphics2D)g;
		
		int x0 = (int)getSize().getWidth()/2;
		int y0 = (int)getSize().getHeight()/2;

		g2d.setColor(Color.YELLOW);
		g2d.drawLine(x0, y0-100, x0, y0+100);
		g2d.drawLine(x0-100, y0, x0+100, y0);
		
		g2d.setColor(Color.WHITE);
		g2d.drawOval(xCursor+x0-5, yCursor+y0-5, 10, 10);
		g2d.drawLine(x0+xCursor, y0+yCursor-10,x0+xCursor,y0+yCursor+10);
		g2d.drawLine(x0+xCursor-10, y0+yCursor, x0+xCursor+10, y0+yCursor);

	}

	@Override
	public void update(Graphics g) {
		super.update(g);		
	}

	
	
}
